Skip to content

Conversation

TorstenDittmann
Copy link
Contributor

@TorstenDittmann TorstenDittmann commented Sep 19, 2025

When serving client files, ensure non-immutable assets are never cached by browsers by setting a maxage=0 cache header.

When no cache-control header is set, browsers will still cache files and with /_app/version.json and /_app/env.js this causes a lot of issues when deploying new versions using the node adapter.

Similiar to what is done here https://github.com/sveltejs/kit/blob/main/packages/kit/src/runtime/server/respond.js#L291-L294

fixes #9089
fixes #13799


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Copy link

changeset-bot bot commented Sep 19, 2025

🦋 Changeset detected

Latest commit: 46c5757

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/adapter-node Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svelte-docs-bot
Copy link

Only static assets should be cached immutably. All other assets should
revalidate to ensure freshness.
@TorstenDittmann TorstenDittmann changed the title fix(node-adapter): set cache header for non-immutable assets fix(node-adapter): set cache header for non-immutable build assets Sep 19, 2025
@benmccann
Copy link
Member

Browsers don't generally cache by default, but from a quick glance it looks like the may use a heuristic to decide such as file extension and may possibly cache. Would probably be good to find a more authoritative reference

If this is an issue, I would guess it's not unique to adapter-node and should be fixed everywhere

@TorstenDittmann
Copy link
Contributor Author

Browsers don't generally cache by default, but from a quick glance it looks like the may use a heuristic to decide such as file extension and may possibly cache. Would probably be good to find a more authoritative reference

If this is an issue, I would guess it's not unique to adapter-node and should be fixed everywhere

Yes, they follow https://datatracker.ietf.org/doc/html/rfc7234#section-4.2.2 and at least for cases I have seen those files are cached.

They actually do it based on 200 responses in general when there is a last-modified header:

@teemingc
Copy link
Member

teemingc commented Sep 24, 2025

I've always wanted to check if version.json was being cached. Is it possible to check if the other adapters need this too and make the necessary changes there? I also wonder if we need to document these cache related rules for adapter-static where the user or platform is usually responsible for serving those files. Might be growing the scope of this PR too much.

@teemingc teemingc changed the title fix(node-adapter): set cache header for non-immutable build assets fix: set cache header for non-immutable build assets Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

generated env.js is missing a cache buster Not found /_app/immutable/assets/xxx
3 participants